let http = require("http")
let url = require("url") // url 解析
let util = require("util") // 工具
let fs = require("fs")  // 文件系统模块

let server = http.createServer((req,res)=>{
	// res.statusCode = 200
	// res.setHeader("Content-Tyep","text/html; charset=utf-8")
	let pathname = url.parse(req.url).pathname
	// console.log()
	let htmlFilePath = `${__dirname}\\${pathname.substring(1)}`
	console.log(htmlFilePath)
	fs.readFile(pathname.substring(1),function(err,data){
		if(err){
			res.writeHead(404,{
				"Content-Tyep":"text/html"
			})
			console.log(err,"err-----")
		}else{
			res.writeHead(200,{
				"Content-Type":"text/html"
			})
			res.write(data.toString())
		}
		res.end()
	})

	

})
server.listen(3000,"127.0.0.1",()=>{
	
	console.log("服务已经启动")
})